package fr.afcepf.ai89.esharing.data;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import fr.afcepf.ai89.esharing.entity.CategorieAem;
import fr.afcepf.ai89.esharing.entity.FrDepartement;
import fr.afcepf.ai89.esharing.entity.TypeAem;

@Stateless
public class DAOCategorieAem implements IDAOCategorieAem {

	@PersistenceContext(unitName = "ESharingPhase22")
	EntityManager em;

	@Override
	public CategorieAem getCatAem(int idCat) {
		
		Query hql = em.createQuery("SELECT c from CategorieAem c WHERE c.idCategorieAem = :param");

		hql.setParameter("param", idCat);
		CategorieAem cat = (CategorieAem)hql.getSingleResult();

		return cat;
	}

	@Override
	public CategorieAem getSuper(CategorieAem cat) {
		
		Query hql = em.createQuery("SELECT c from CategorieAem c WHERE c.idCategorieAem = :param");

		hql.setParameter("param", cat.getCategorieAem().getIdCategorieAem());
		CategorieAem superChat = (CategorieAem)hql.getSingleResult();

		return superChat;
	}

	@Override
	public CategorieAem getParent(TypeAem type) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<CategorieAem> getCatsRacines() {
		
		Query hql = em.createQuery("SELECT c from CategorieAem c WHERE c.categorieAem IS NULL");

		List<CategorieAem> cats = (List<CategorieAem>)hql.getResultList();

		return cats;

	}

	@Override
	public List<CategorieAem> getCats() {
		
		Query hql = em.createQuery("SELECT c from CategorieAem c");

		List<CategorieAem> cats = (List<CategorieAem>)hql.getResultList();

		return cats;

	}

	@Override
	public List<CategorieAem> getSousCats(CategorieAem cat) {
		
		Query hql = em.createQuery("SELECT c from CategorieAem c WHERE c.categorieAem.idCategorieAem = :param");

		hql.setParameter("param", cat.getIdCategorieAem());
		List<CategorieAem> cats = (List<CategorieAem>)hql.getResultList();

		return cats;

	}

	@Override
	public int addCatAem(CategorieAem cat) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int majCatAem(CategorieAem cat) {
		// TODO Auto-generated method stub
		return 0;
	}

}
